package com.usian.behavior.kafka;

import com.alibaba.fastjson.JSON;
import com.usian.behavior.service.FollowBehaviorService;
import com.usian.common.constants.NewsConstant;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class FollowMessageListener {
    @Autowired
    private FollowBehaviorService behaviorService;
    @KafkaListener(topics = NewsConstant.USER_FOLLOW_BEHAVIOR)
    public void getMessage(ConsumerRecord record){
        if (record != null && record.value() != null){
            String json = (String) record.value();
            Map map = JSON.parseObject(json, Map.class);
            Boolean save = behaviorService.followBehaviorSave(map);
            System.out.println("关注行为保存"+(save?"成功":"失败"));
        }
    }
}
